package lol.oxguy3.hellotoast;

import com.oxguy3.hellotoast.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.TableLayout;
import android.widget.TextView;
import android.widget.Toast;

public class HelloToastActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button enterbtn = new Button(this);//(Button) findViewById(R.id.buttonEnter);
        enterbtn.setText("Enter");
        enterbtn.setOnClickListener(new OnClickListener(){

			public void onClick(View v) {
				doEverything();
			}
        	
        });
        //this.
        ((TableLayout) findViewById(R.id.tableLayoutForm)).addView(enterbtn);//addContentView(enterbtn, null);
        
        /*Spinner spinnerAges = (Spinner) findViewById(R.id.spinnerAges);//new Spinner(this);
        ArrayAdapter<CharSequence> spinnerAgesAd = ArrayAdapter.createFromResource(this, R.array.ages_arr, android.R.layout.simple_spinner_item);
        spinnerAgesAd.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinnerAges.setAdapter(spinnerAgesAd);*/
        
        SeekBar seekBarAges = (SeekBar) findViewById(R.id.seekBarAges);
        seekBarAges.setMax(4);
        seekBarAges.setProgress(0);
        seekBarAges.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
			
			public void onStopTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
				
			}
			
			public void onStartTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
				
			}
			
			public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
				((TextView) findViewById(R.id.textViewAgesValue)).setText(String.valueOf(progress+13).toCharArray(), 0, String.valueOf(progress+13).length());
				
			}
		});
        
        
        Spinner spinnerCourses = (Spinner) findViewById(R.id.spinnerCourses);//new Spinner(this);
        ArrayAdapter<CharSequence> spinnerCoursesAd = ArrayAdapter.createFromResource(this, R.array.courses_arr, android.R.layout.simple_spinner_item);
        spinnerCoursesAd.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinnerCourses.setAdapter(spinnerCoursesAd);
    }
    
    public void doEverything() {
    	String toasty = "Input received!\n";
		
		toasty += "Name: ";
		toasty += ((EditText) findViewById(R.id.editTextName)).getText().toString();
		toasty += "\n";
		
		toasty += "Age: ";
		toasty += Integer.toString(((int)((SeekBar) findViewById(R.id.seekBarAges)).getProgress())+13);//getResources().getStringArray(R.array.ages_arr)[(int)((Spinner)findViewById(R.id.spinnerAges)).getSelectedItemId()];
		toasty += "\n";
		
		toasty += "Hometown: ";
		toasty += ((EditText) findViewById(R.id.editTextHometown)).getText().toString();
		toasty += "\n";
		
		toasty += "Room #: ";
		toasty += ((EditText) findViewById(R.id.editTextRoom)).getText().toString();
		toasty += "\n";
		
		toasty += "Course: ";
		toasty += getResources().getStringArray(R.array.courses_arr)[(int)((Spinner) findViewById(R.id.spinnerCourses)).getSelectedItemId()];
		toasty += "\n";
		
		Toast.makeText(getApplicationContext(), toasty, Toast.LENGTH_LONG).show();
    }
}